package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.VO.OperatorVO;
import com.company.project.model.VtManager;
import com.company.project.service.VtManagerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2023/10/17.
*/
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/vt/manager")
public class VtManagerController {
    @Resource
    private VtManagerService vtManagerService;

    @PostMapping("/add")
    public Result add(VtManager vtManager) {
        vtManagerService.save(vtManager);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        vtManagerService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(VtManager vtManager) {
        vtManagerService.update(vtManager);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        VtManager vtManager = vtManagerService.findById(id);
        return ResultGenerator.genSuccessResult(vtManager);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<VtManager> list = vtManagerService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
    @GetMapping("/findAssembleDirector")
    public Result findAssembleDirector() {
        List<OperatorVO> list = vtManagerService.findAssembleDirector();
        return ResultGenerator.genSuccessResult(list);
    }

}
